package com.j180.Advice;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Aspect
@Component
public class MyLogAdvice {

    @Pointcut("execution(* com.j180.dao..*(..))")
    public void mypintCut(){}

    @Around("mypintCut()")
    public Object getLogerformDaoImpl(ProceedingJoinPoint jp){

        System.out.println(jp.getSignature().getName()+"方法执行前");
        Object obj=null;
        try {
             obj =  jp.proceed();

            System.out.println(jp.getTarget().getClass().getName()+"在"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))+"执行了"+jp.getSignature().getName());
            System.out.println("传递的参数为：");
             Object[] parms =  jp.getArgs();
            for (Object parm : parms) {
                System.out.println(parm.toString());
            }
            System.out.println("方法的返回值的为："+obj);

            System.out.println("-----------------------------------------");

        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

        return obj;
    }

}
